<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>运营管理</el-breadcrumb-item>
        <el-breadcrumb-item>Banner管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <router-link to="/banner/add">
      <el-button type="success" class="add-btn">新增轮播</el-button>
    </router-link>
    <el-table border :data="tableData.list">
      <el-table-column
        label="ID"
        sortable
        align="center"
        prop="id"
      ></el-table-column>
      <el-table-column
        label="图片"
        sortable
        align="center"
        prop="imageUrl"
        width="300px"
      >
        <template slot-scope="scope">
          <el-image
            class="banner-img"
            :src="scope.row.imageUrl"
            :preview-src-list="[scope.row.imageUrl]"
          ></el-image>
        </template>
      </el-table-column>

      <el-table-column
        label="排序"
        sortable
        align="center"
        prop="sort"
      ></el-table-column>
      <el-table-column
        label="链接网址"
        sortable
        align="center"
        prop="addressUrl"
      ></el-table-column>

      <el-table-column label="创建时间" sortable align="center" prop="createTime">
        <template slot-scope="scope">
          {{ $moment(scope.row.createTime).format("YYYY-MM-DD hh:mm:ss") }}
        </template>
      </el-table-column>
      <el-table-column label="下架时间" sortable align="center" prop="offTime">
        <template slot-scope="scope">
          {{ $moment(scope.row.offTime).format("YYYY-MM-DD hh:mm:ss") }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="类型" align="center">
        <template slot-scope="scope">
          {{ ["园区", "企业园区"][scope.row.type] }}
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          {{ ["上架", "下架"][scope.row.status] }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="`/banner/edit/${scope.row.id}`">
            <el-button type="text">详情/编辑</el-button>
          </router-link>
          <el-button
            type="text"
            class="margin-left"
            @click="deleteInfo(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="search"
      @current-change="search"
      :current-page.sync="page"
      :page-sizes="[10, 25, 50, 100]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.total"
    ></el-pagination>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      tableData: {
        list: [],
        total: 0,
      },
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    search() {
      let params = {
        pageNum: this.page,
        pageSize: this.pageSize,
        ...this.searchForm,
      };
      this.$axios.post("/sysBannerUrl/list", params).then((result) => {
        if (result) {
          this.tableData = {
            list: result.data.list,
            total: result.data.total,
          };
        } else {
          this.$message.error(result.data.msg);
        }
      });
    },
    /**
     * @dev 删除
     */
    deleteInfo(id) {
      const _this = this;
      this.$confirm("确定删除该轮播图广告信息？", "确认删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnPressEscape: false,
        closeOnClickModal: false,
      })
        .then(() => {
          _this.$axios.delete(`/sysBannerUrl/delete/${id}`).then((res) => {
            if (res.code == 200) {
              this.$message.success("操作成功");
              this.search();
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message.warning("操作已取消");
        });
    },
  },
  created() {
    this.search();
  },
};
</script>

<style scoped lang="scss">
.add-btn {
  margin: 15px 0;
}
.banner-img {
  height: 150px;
  width: 200px;
}
</style>
